// var moren = {
	// 	"imgs": [],
	// 	"scrolltime": 2000,
	// 	"iconcolor": "white",
	// 	"iconhover": "skyblue",
	// 	"donghua": "all 1s"
	// };

;(function($){

	var moren = {
		"imgs": [],
		"scrolltime": 2000,
		"iconcolor": "white",
		"iconhover": "skyblue",
		"donghua": "all 1s"
	};


	$.fn.extend({

		"myscroll": function(canshu){
			var shiji = $.extend({},moren,canshu);

			$(this).append("<div class='dabox'></div>");
			$(".dabox").append("<ul class='dabox-main'></ul>");
			$(".dabox").append("<div class='dabox-cont'></div>");

			$.each(shiji.imgs,function(index,value){
				console.log(value);
				var li = $("<li></li>");
				var a = $("<a href="+value.href+" target='_blank'></a>");
				var img = $("<img src="+value.src+" title="+value.title+">");
				a.append(img);
				li.append(a);

				$(".dabox-main").append(li);

				var span = $("<span></span>");
				$(".dabox-cont").append(span);
			});

			var dabox_w = $(this).width();
			var dabox_h = $(this).height();

			$(".dabox").css({
				"width": "100%",
				"height": "100%",
				"overflow": "hidden",
				"position": "relative"
			});

			$(".dabox-main").css({
				"width": "10000px"
			});

			$(".dabox-main li").css({
				"width": dabox_w,
				"height": dabox_h,
				"float": "left"
			});

			$(".dabox-main li img").css({
				"width": "100%",
				"height": "100%"
			});

			$(".dabox-cont").css({
				"position": "absolute",
				"left": "50%",
				"bottom": "10px",
				"transform": "translateX(-50%)",
				"text-align": "center"

			});

			$(".dabox-cont span").css({

			"display": "inline-block",
			"width": "10px",
			"height": "10px",
			"border-radius": "5px",
			"margin": "0px 5px",
			"background": shiji.iconcolor

			});

			$(".dabox-cont span").eq(0).css("background",shiji.iconhover);

			var timer = null;
			var index = 0;
			function play(){
				index++;

				if(index > shiji.imgs.length-1){
					index = 0;
				}

				$(".dabox-main").css({
					"transition": shiji.donghua,
					"transform": "translate3d("+(-index*dabox_w)+"px,0px,0px)"
				});

				$(".dabox-cont span").eq(index).css("background",shiji.iconhover)
									.siblings().css("background",shiji.iconcolor);
				timer = setTimeout(play,shiji.scrolltime);
			}

			timer = setTimeout(play,shiji.scrolltime);

			$(this).on("mouseenter",function(){
				clearTimeout(timer);
			});

			$(this).on("mouseleave",function(){
				timer = setTimeout(play,shiji.scrolltime);
			});

			$(".dabox-cont span").on("mouseenter",function(){
				var $index = $(this).index();
				index = $index;

				$(".dabox-main").css({
					"transition": shiji.donghua,
					"transform": "translate3d("+(-index*dabox_w)+"px,0px,0px)"
				});

				$(".dabox-cont span").eq(index).css("background",shiji.iconhover)
									.siblings().css("background",shiji.iconcolor);

			});

			return this;

		}

	});



})(jQuery);